package com.shuqi.model.parse.parser;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import com.shuqi.common.utils.Log4an;
import com.shuqi.model.bean.OfferWallInfo;
import com.shuqi.model.parse.HandlerBase;

/**
 * 推广墙列表解析
 * 
 * @author linyuren
 * 
 */
public class OfferWallParser extends HandlerBase {

    private List<OfferWallInfo> offerWallInfoList;// 推广列表的集合
    private OfferWallInfo offerWallInfo; // 推广墙对象

    private String lineSize;
    private String topSize;
    private String pageCount;

    @Override
    public List<OfferWallInfo> getParsedData() {
        return this.offerWallInfoList;
    }

    @Override
    public void startDocument() throws SAXException {
        this.offerWallInfoList = new ArrayList<OfferWallInfo>();
    }

    @Override
    public void startElement(String uri, String localName, String qName, Attributes attrs)
            throws SAXException {
        if (localName.equals("offerwall")) {
            this.lineSize = isNull(attrs, "linesize");
            this.topSize = isNull(attrs, "topsize");
            this.pageCount = isNull(attrs, "pagecount");
        } else if (localName.equals("item")) {
            this.offerWallInfo = new OfferWallInfo();
            this.offerWallInfo.setItemId(isNull(attrs, "itemid"));
            this.offerWallInfo.setIconUrl(isNull(attrs, "img"));
            this.offerWallInfo.setIntro(isNull(attrs, "intro"));
            this.offerWallInfo.setName(isNull(attrs, "name"));
            this.offerWallInfo.setChannel(isNull(attrs, "channel"));
            this.offerWallInfo.setDownloadUrl(isNull(attrs, "url"));
            this.offerWallInfo.setSize(isNull(attrs, "size"));
            this.offerWallInfo.setPackageName(isNull(attrs, "packagename"));
            this.offerWallInfo.setVersionCode(isNull(attrs, "versioncode"));
            this.offerWallInfo.setGroom(isNull(attrs, "groom"));
            this.offerWallInfo.setLineSize(lineSize);
            this.offerWallInfo.setTopSize(topSize);
            this.offerWallInfo.setPageCount(pageCount);
            this.offerWallInfoList.add(this.offerWallInfo);
        }
    }

    @Override
    public void endDocument() throws SAXException {
        super.endDocument();
    }

}
